<template>
    <div class="container">
        <div class="title">
            <span>添加</span>
            <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
        </div>
        <el-divider></el-divider>
        <br/>
        <el-form label-width="120px"
                 :model="form"
                 status-icon
                 ref="form"
                 @submit.native.prevent>
                <el-form-item label="用户姓名" prop="name">
                    <el-input size="medium" v-model="form.name" placeholder="请填写用户姓名"></el-input>
                </el-form-item>
                <el-form-item label="用户手机号" prop="phone">
                    <el-input size="medium" type="number" v-model="form.phone" placeholder="请填写用户手机号"></el-input>
                </el-form-item>
                <el-form-item label="订房订单号" prop="order_no">
                    <el-input size="medium" v-model="form.order_no" placeholder="请填写订房订单号"></el-input>
                </el-form-item>
                <el-form-item label="说明" prop="explain">
                    <el-input v-model="form.explain"
                              type="textarea"
                              :rows="5"
                              placeholder="请填写说明"></el-input>
                </el-form-item>
            <el-form-item class="submit" style="margin-top: 30px;">
                <el-button type="primary" @click="submitForm()">保 存</el-button>
                <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import records from '@/models/records'
import User from '@/lin/models/user'

export default {
  data() {
    return {
      form: {
        lin_user_id: '',
        name: '',
        phone: '',
        order_no: '',
        explain: '',
      },
    }
  },
  created() {
    this.getAdminUser()
  },
  methods: {
    async getAdminUser() {
      const res = await User.getInformation()
      this.form.lin_user_id = res.linUserId
    },
    async submitForm() {
      const self = this
      // eslint-disable-next-line no-unused-vars
      const info = {
        lin_user_id: self.form.lin_user_id,
        name: self.form.name,
        phone: self.form.phone,
        order_no: self.form.order_no,
        explain: self.form.explain,
      }
      try {
        // eslint-disable-next-line no-unused-vars
        const res = await records.createRecords(info)
        if (res.error_code === 0) {
          this.$message.success(`${res.msg}`)
          this.back()
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    back() {
      this.$emit('addClose')
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
